package com.music.mysongs.bean

import android.net.Uri
import com.music.mysongs.db.MusicDataBaseManager
import com.music.mysongs.utils.myLog

class BeanManager {
    private val localList = ArrayList<SongBean>()
    private val loveList = ArrayList<SongBean>()
    private val dbManager = MusicDataBaseManager()

    init {
        dbManager.queryLocalDB(localList)
        dbManager.queryLoveDB(loveList) }
    fun getBeanArr(love: Boolean): ArrayList<SongBean> {
        return if (love) { loveList } else { localList }
    }

    fun getBeanList(pos: Int, love: Boolean): SongBean {
        return if (love) {
            loveList[pos]
        } else {
            localList[pos]
        }
    }

    fun getBeanSize(love: Boolean): Int {
        return if (love) {
            loveList.size
        } else {
            localList.size
        }
    }

    fun getIsLove(path: Uri): Boolean {
        return dbManager.queryExistDB(path)
    }

    fun setBeanLove(bean: SongBean) {
        if (dbManager.queryExistDB(bean.path!!)) {
            loveList.remove(bean)
            dbManager.deleteDB(bean.path!!)
        } else {
            loveList.add(bean)
            dbManager.insertDB(bean)
        }
    }
}